import {SocketManager} from "./socket";
import config from "./config";
import {coreInit} from "./core";

const Koa = require('koa');

const app = new Koa();
const IO = require('koa-socket');
const socket = new IO({});

socket.attach(app);

app.context.config = config;
app.io.app = app;
app.io.manager = new SocketManager(app.io);

//初始化
app.use(async (ctx: any, next: any) => {
    ctx.io = app.io;
    ctx.config = config;
    return await next();
});

coreInit(app);

//安装所有其他的事件程序
const LISTEN_PORT = config.server.port;

//末尾捕获异常
app.use(async (ctx: any) => {
    return ctx.json({message: '404 Not Found', code: 1001}, 404);
});

app.listen(LISTEN_PORT, () => console.log(`Running on localhost：${LISTEN_PORT}`));



